Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 344)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.51074 11.55187 11.59253 11.63273 11.67248 11.71181 11.75073 11.78925
## [9] 11.82739 11.86516 11.90259 11.93968 11.97646 12.01292 12.04902 12.08475
## [17] 12.12007 12.15497 12.18943 12.22342 12.25692 12.28990 12.32262 12.35530
## [25] 12.38784 12.42016 12.45217 12.48379 12.51492 12.54549 12.57539 12.60456
## [33] 12.63289 12.66031 12.68787 12.71636 12.74534 12.77433 12.80289 12.83054
## [41] 12.85682 12.88127 12.90344 12.92509 12.94799 12.97165 12.99557 13.01928
## [49] 13.04229 13.06411 13.08425 13.10222 13.11754 13.12972 13.13828 13.14472
## [57] 13.15065 13.15575 13.15971 13.16221 13.16291 13.16151 13.15768 13.15111
## [65] 13.14043 13.12496 13.10542 13.08250 13.05690 13.02933 13.00049 12.97107
## [73] 12.94179 12.91334 12.88643 12.86175 12.83433 12.80002 12.76076 12.71851
## [81] 12.67521 12.63281 12.59327 12.55852 12.53052 12.50604 12.48078 12.45502
## [89] 12.42906 12.40321 12.37774 12.35297 12.32918 12.30668 12.28575 12.26670
## [97] 12.24982 12.23519 12.22250 12.21143 12.20169 12.19297 12.18497 12.17739
## [105] 12.16992 12.16227 12.15537 12.15024 12.14667 12.14446 12.14340 12.14329
## [113] 12.14392 12.14509 12.14659 12.14822 12.14977 12.15105 12.15316 12.15706
## [121] 12.16235 12.16859 12.17536 12.18222 12.18877 12.19457 12.19920 12.20394
## [129] 12.21016 12.21754 12.22577 12.23454 12.24354 12.25245 12.26097 12.26879
## [137] 12.27559 12.28105 12.28488 12.28649 12.28580 12.28325 12.27929 12.27436
## [145] 12.26891 12.26339 12.25823 12.25388 12.25078 12.24938 12.25013 12.25346
## [153] 12.25983 12.26650 12.27103 12.27429 12.27714 12.28043 12.28503 12.29179
## [161] 12.30159 12.31527 12.33301 12.35373 12.37648 12.40028 12.42418 12.44721
## [169] 12.46840 12.49153 12.52051 12.55455 12.59291 12.63479 12.67944 12.72608
## [177] 12.77395 12.82228 12.87029 12.91721 12.96228 13.00473 13.04378 13.07868
## [185] 13.10863 13.13289 13.15067 13.16121 13.16794 13.17444 13.18014 13.18449
## [193] 13.18693 13.18692 13.18388 13.17727 13.16653 13.14878 13.12241 13.08875
## [201] 13.04913 13.00489 12.95734 12.90784 12.85770 12.80826 12.76085 12.71680
## [209] 12.67745 12.63792 12.59337 12.54516 12.49467 12.44325 12.39227 12.34310
## [217] 12.29710 12.25565 12.21599 12.17474 12.13234 12.08923 12.04583 12.00258
## [225] 11.95991 11.91826 11.87806 11.83974 11.80374 11.77049 11.73818 11.70508
## [233] 11.67176 11.63876 11.60663 11.57594 11.54724 11.52107 11.49799 11.47655
## [241] 11.45511 11.43400 11.41352 11.39399 11.37572 11.35903 11.34424 11.33165
## [249] 11.32159 11.31436 11.31028 11.30888 11.30945 11.31190 11.31615 11.32212
## [257] 11.32973 11.33889 11.34952 11.36155 11.37821 11.40192 11.43139 11.46534
## [265] 11.50247 11.54150 11.58114 11.62010 11.65708 11.69081 11.72000 11.74334
## [273] 11.76600 11.79306 11.82316 11.85490 11.88693 11.91786 11.94631 11.97092
## [281] 11.99030 12.00515 12.01735 12.02739 12.03572 12.04281 12.04912 12.05512
## [289] 12.06127 12.06802 12.07586 12.08524 12.09661 12.10680 12.11304 12.11646
## [297] 12.11815 12.11926 12.12088 12.12415 12.13017 12.14007 12.15267 12.16597
## [305] 12.17987 12.19429 12.20914 12.22430 12.23970 12.25523 12.27080 12.28632
## [313] 12.30170 12.31683 12.33163 12.34599 12.36043 12.37545 12.39095 12.40683
## [321] 12.42300 12.43935 12.45580 12.47223 12.48856 12.50468 12.52051 12.53593
## [329] 12.55124 12.56675 12.58240 12.59812 12.61383 12.62949 12.64502 12.66035
## [337] 12.67542 12.69001 12.70405 12.71764 12.73093 12.74402 12.75706 12.77016
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 344)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.73187 10.82230 10.91097 10.99785 11.08292 11.16617 11.24757 11.32712
## [9] 11.40479 11.48056 11.55441 11.62634 11.69632 11.76434 11.83045 11.89467
## [17] 11.95704 12.01757 12.07631 12.13329 12.18853 12.24206 12.29366 12.34313
## [25] 12.39054 12.43597 12.47950 12.52120 12.56115 12.59941 12.63607 12.67121
## [33] 12.70489 12.73719 12.76753 12.79541 12.82108 12.84475 12.86668 12.88709
## [41] 12.90621 12.92428 12.94154 12.95625 12.96690 12.97407 12.97833 12.98024
## [49] 12.98037 12.97929 12.97758 12.97580 12.97451 12.97430 12.97573 12.97711
## [57] 12.97664 12.97472 12.97173 12.96806 12.96411 12.96028 12.95694 12.95449
## [65] 12.95282 12.95142 12.95010 12.94867 12.94696 12.94476 12.94190 12.93818
## [73] 12.93343 12.92745 12.92005 12.91105 12.90040 12.88833 12.87510 12.86093
## [81] 12.84609 12.83081 12.81534 12.79992 12.78480 12.77018 12.75599 12.74203
## [89] 12.72809 12.71398 12.69951 12.68448 12.66869 12.65195 12.63406 12.61482
## [97] 12.59403 12.57079 12.54470 12.51641 12.48653 12.45569 12.42451 12.39362
## [105] 12.36363 12.33517 12.30375 12.26551 12.22204 12.17495 12.12582 12.07626
## [113] 12.02785 11.98220 11.94089 11.90553 11.87770 11.85901 11.84590 11.83391
## [121] 11.82320 11.81398 11.80642 11.80073 11.79708 11.79568 11.79669 11.80124
## [129] 11.80992 11.82214 11.83731 11.85487 11.87422 11.89479 11.91598 11.93722
## [137] 11.95793 11.97752 11.99541 12.01485 12.03901 12.06721 12.09877 12.13300
## [145] 12.16922 12.20673 12.24485 12.28290 12.32019 12.35604 12.38976 12.42066
## [153] 12.44806 12.47363 12.49940 12.52526 12.55110 12.57679 12.60221 12.62725
## [161] 12.65179 12.67572 12.69737 12.71588 12.73227 12.74757 12.76282 12.77904
## [169] 12.79728 12.81830 12.84195 12.86785 12.89563 12.92490 12.95528 12.98639
## [177] 13.01785 13.04928 13.08030 13.11054 13.13960 13.16712 13.19271 13.21599
## [185] 13.23658 13.25410 13.26817 13.27842 13.28671 13.29489 13.30252 13.30914
## [193] 13.31431 13.31759 13.31853 13.31669 13.31161 13.30328 13.29209 13.27828
## [201] 13.26206 13.24366 13.22329 13.20118 13.17755 13.15261 13.12659 13.09971
## [209] 13.07219 13.04153 13.00583 12.96622 12.92381 12.87974 12.83513 12.79111
## [217] 12.74881 12.70934 12.66868 12.62272 12.57252 12.51912 12.46355 12.40687
## [225] 12.35010 12.29430 12.24049 12.18974 12.14307 12.10154 12.06187 12.02057
## [233] 11.97829 11.93570 11.89345 11.85221 11.81264 11.77540 11.74115 11.70866
## [241] 11.67643 11.64468 11.61366 11.58360 11.55476 11.52735 11.50163 11.47783
## [249] 11.45619 11.43695 11.42035 11.40588 11.39294 11.38155 11.37179 11.36370
## [257] 11.35734 11.35275 11.34999 11.34911 11.35094 11.35597 11.36381 11.37406
## [265] 11.38630 11.40014 11.41516 11.43097 11.44716 11.46332 11.47905 11.49395
## [273] 11.51061 11.53125 11.55494 11.58069 11.60757 11.63462 11.66087 11.68536
## [281] 11.70716 11.72879 11.75314 11.77972 11.80804 11.83763 11.86800 11.89866
## [289] 11.92913 11.95894 11.98759 12.01461 12.03950 12.06284 12.08559 12.10784
## [297] 12.12968 12.15120 12.17249 12.19366 12.21479 12.23597 12.25734 12.27890
## [305] 12.30056 12.32224 12.34385 12.36529 12.38649 12.40734 12.42778 12.44769
## [313] 12.46701 12.48563 12.50347 12.52044 12.53687 12.55310 12.56909 12.58482
## [321] 12.60023 12.61530 12.62999 12.64425 12.65805 12.67135 12.68412 12.69632
## [329] 12.70805 12.71943 12.73045 12.74107 12.75126 12.76099 12.77024 12.77899
## [337] 12.78720 12.79478 12.80169 12.80800 12.81375 12.81899 12.82378 12.82817
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 344)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.84430 10.90640 10.96744 11.02737 11.08618 11.14384 11.20033 11.25560
## [9] 11.30965 11.36245 11.41396 11.46416 11.51304 11.56063 11.60705 11.65230
## [17] 11.69640 11.73937 11.78122 11.82197 11.86163 11.90022 11.93737 11.97279
## [25] 12.00660 12.03895 12.06996 12.09977 12.12851 12.15631 12.18331 12.20963
## [33] 12.23542 12.26080 12.28502 12.30743 12.32833 12.34801 12.36677 12.38490
## [41] 12.40270 12.42046 12.43847 12.45730 12.47706 12.49739 12.51793 12.53832
## [49] 12.55820 12.57721 12.59499 12.61118 12.62541 12.63734 12.64660 12.65348
## [57] 12.65863 12.66224 12.66447 12.66549 12.66549 12.66462 12.66308 12.66102
## [65] 12.65801 12.65355 12.64777 12.64078 12.63268 12.62360 12.61364 12.60293
## [73] 12.59157 12.57968 12.56737 12.55476 12.53943 12.51963 12.49647 12.47106
## [81] 12.44450 12.41792 12.39241 12.36908 12.34905 12.32955 12.30749 12.28345
## [89] 12.25804 12.23185 12.20548 12.17952 12.15457 12.13122 12.11006 12.09170
## [97] 12.07673 12.06474 12.05467 12.04612 12.03870 12.03200 12.02563 12.01920
## [105] 12.01231 12.00457 11.99686 11.99026 11.98457 11.97964 11.97529 11.97135
## [113] 11.96765 11.96402 11.96029 11.95628 11.95183 11.94677 11.94224 11.93926
## [121] 11.93748 11.93657 11.93617 11.93594 11.93553 11.93460 11.93279 11.93046
## [129] 11.92814 11.92580 11.92340 11.92091 11.91828 11.91549 11.91248 11.90924
## [137] 11.90571 11.90186 11.89766 11.89132 11.88155 11.86908 11.85461 11.83886
## [145] 11.82253 11.80635 11.79103 11.77728 11.76581 11.75734 11.75259 11.75225
## [153] 11.75705 11.76540 11.77520 11.78638 11.79891 11.81273 11.82778 11.84401
## [161] 11.86138 11.87982 11.90152 11.92770 11.95686 11.98753 12.01822 12.04745
## [169] 12.07373 12.10105 12.13395 12.17173 12.21370 12.25918 12.30746 12.35787
## [177] 12.40972 12.46231 12.51496 12.56697 12.61766 12.66633 12.71231 12.75489
## [185] 12.79339 12.82712 12.85539 12.87751 12.89723 12.91813 12.93928 12.95974
## [193] 12.97859 12.99488 13.00769 13.01608 13.01911 13.01658 13.00925 12.99766
## [201] 12.98239 12.96396 12.94295 12.91990 12.89536 12.86989 12.84404 12.81836
## [209] 12.79340 12.76472 12.72869 12.68714 12.64189 12.59475 12.54755 12.50209
## [217] 12.46019 12.42368 12.38725 12.34515 12.29859 12.24874 12.19681 12.14397
## [225] 12.09142 12.04034 11.99193 11.94738 11.90786 11.87458 11.84322 11.80944
## [233] 11.77439 11.73923 11.70511 11.67318 11.64458 11.62048 11.60202 11.59037
## [241] 11.58518 11.58540 11.58995 11.59774 11.60772 11.61881 11.62993 11.64000
## [249] 11.64797 11.65274 11.65326 11.65365 11.65806 11.66544 11.67473 11.68487
## [257] 11.69481 11.70350 11.70987 11.71287 11.71249 11.70977 11.70528 11.69954
## [265] 11.69313 11.68658 11.68045 11.67528 11.67162 11.67003 11.67104 11.67522
## [273] 11.67996 11.68277 11.68436 11.68546 11.68680 11.68908 11.69304 11.69939
## [281] 11.70885 11.72182 11.73782 11.75631 11.77674 11.79854 11.82118 11.84409
## [289] 11.86672 11.88853 11.90896 11.92745 11.94346 11.96096 11.98339 12.00936
## [297] 12.03751 12.06646 12.09483 12.12123 12.14430 12.16266 12.17719 12.18986
## [305] 12.20096 12.21078 12.21958 12.22766 12.23529 12.24276 12.25035 12.25834
## [313] 12.26701 12.27663 12.28751 12.29990 12.31270 12.32472 12.33613 12.34713
## [321] 12.35790 12.36861 12.37945 12.39061 12.40226 12.41459 12.42778 12.44202
## [329] 12.45684 12.47172 12.48671 12.50189 12.51732 12.53307 12.54922 12.56582
## [337] 12.58294 12.60085 12.61968 12.63927 12.65948 12.68014 12.70110 12.72221
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")